package com.example.tests;

import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;
import java.util.Random;

import org.testng.annotations.Test;

public class PersonRemovalTests extends TestBase {
	
	@Test
	public void deleteSomePerson() {
		app.getNavigationHelper().openMainPage();
	    
	    // save old state
	    List<PersonData> oldList = app.getPersonHelper().getPersons();
	    
	    Random rnd = new Random();
		int index = rnd.nextInt(oldList.size()-1);
	    
	    //actions   
		app.getPersonHelper().initPersonEditing(index);
		app.getPersonHelper().deleteCurrentPerson();
		app.getPersonHelper().returnToHomePage();
			  
	    //save new state
	    List<PersonData> newList = app.getPersonHelper().getPersons();
	    
	    //compare states
	    oldList.remove(index);
	    Collections.sort(oldList);
	    assertEquals(newList, oldList);
	}

	@Test
	public void alsoDeleteSomePerson() {
		app.getNavigationHelper().openMainPage();
	    
	    // save old state
	    List<PersonData> oldList = app.getPersonHelper().getPersons();
	    
	    Random rnd = new Random();
		int index = rnd.nextInt(oldList.size()-1);
	    
	    //actions 
		app.getPersonHelper().initPersonView(index);
		app.getPersonHelper().initPersonModification();
		app.getPersonHelper().deleteCurrentPerson();
		app.getPersonHelper().returnToHomePage();
		
	    //save new state
	    List<PersonData> newList = app.getPersonHelper().getPersons();
	    
	    //compare states
	    oldList.remove(index);
	    Collections.sort(oldList);
	    assertEquals(newList, oldList);
	}
}
